package com.qf.fmall2302.index.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.fmall2302.index.entity.Category;
import com.qf.fmall2302.index.entity.IndexImg;
import com.qf.fmall2302.index.service.ICategoryService;
import com.qf.fmall2302.index.service.IIndexImgService;
import com.qf.fmall2302.product.entity.Product;
import com.qf.fmall2302.product.service.IProductService;
import com.qf.fmall2302.utils.FmallConstants;
import com.qf.fmall2302.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 轮播图  前端控制器
 * </p>
 *
 * @author dongjl
 * @since 2023-08-23
 */
@RestController
@RequestMapping("/index")
@CrossOrigin
public class IndexImgController {

    @Autowired
    IIndexImgService iIndexImgService;

    @Autowired
    ICategoryService categoryService;

    @Autowired
    IProductService productService;

    @GetMapping("category-recommends")
    public ResultVo categoryRecommends(){

        List<Category> data = categoryService.categoryRecommends();
        return ResultVo.ok(FmallConstants.SUCCESS_CODE, FmallConstants.SUCCESS_MSG, data);
    }

    @GetMapping("/list-recommends")
    public ResultVo listRecommends(){
        List<Product> data = productService.listRecommends();
        return ResultVo.ok(FmallConstants.SUCCESS_CODE, FmallConstants.SUCCESS_MSG, data);
    }

    @GetMapping("/category-list")
    public ResultVo categoryList() throws Exception {
       List<Category> data =  categoryService.categoryList();
        return ResultVo.ok(FmallConstants.SUCCESS_CODE, FmallConstants.SUCCESS_MSG, data);
    }


    @GetMapping("/indeximg")
    public ResultVo indeximg(){

        List<IndexImg> data = iIndexImgService.list(new QueryWrapper<IndexImg>().eq("status", 1).orderByDesc("seq"));

        return ResultVo.ok(FmallConstants.SUCCESS_CODE, FmallConstants.SUCCESS_MSG, data);

    }

}
